package leetcode.weekly.week307;

//Solution1Test
public class Solution1 {

	public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
		int a = 0, b = 0;
		for (int i = 0; i < experience.length; i++) {
			int e = energy[i], exp = experience[i];
			if (initialEnergy > e) {
				initialEnergy -= e;
			} else {
				a += e - initialEnergy + 1;
				initialEnergy = 1;
			}
			if (initialExperience <= exp) {
				b += exp - initialExperience + 1;
				initialExperience = exp + 1;
			}
			initialExperience += exp;
		}
		return a + b;
	}

}
